﻿// Copyright (c) 2017 GlassGrass

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace GlassGrass.Unity.GuiFramework
	{
	/// <summary> Static utility members without any side-effects. </summary>
	public static class Utility
		{

		/// <summary> Name of this assembly. </summary>
		public static string AssemblyName
			=> System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;



		/// <summary> Ensure that the Rect remains within the screen bounds.
		/// </summary>.
		/// <param name="r">The clamping target rect</param>
		public static Rect ClampToScreen(this Rect r) => r.ClampToScreen( new RectOffset( 0, 0, 0, 0 ) );



		/// <summary> Ensure that the Rect remains within the screen bounds. </summary>
		/// <param name="r"> The clamping target rect </param>
		/// <param name="screenBorder"> A Border to the screen bounds that the Rect will be clamped inside (can be negative) </param>
		public static Rect ClampToScreen(this Rect r, RectOffset screenBorder)
			{
			r.x = Mathf.Clamp( r.x, screenBorder.left, Screen.width - r.width - screenBorder.right );
			r.y = Mathf.Clamp( r.y, screenBorder.top, Screen.height - r.height - screenBorder.bottom );
			return r;
			}
		}
	}
